package com.myproject.mall.goods.service.impl;

import com.myproject.mall.common.exception.GlobalException;
import com.myproject.mall.domain.dto.GoodsDTO;
import com.myproject.mall.domain.entity.Goods;
import com.myproject.mall.goods.mapper.GoodsMapper;
import com.myproject.mall.goods.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class GoodsServiceImpl  implements IGoodsService {

    @Autowired
    private GoodsMapper goodsMapper;
    @Autowired
    private StringRedisTemplate redisTemplate;


    @Override
    public GoodsDTO getGoodsDetail(Long goodsId) {
//        TODO: 获取商品详情
        return null;
    }

    @Override
    public Long addGoods(Long shopId, Goods goods) {
        goods.setShopId(shopId);
        int insert = goodsMapper.insert(goods);
        if(insert == 0) throw new GlobalException("添加失败");
        return goods.getId();
    }

    @Override
    public void offlineGoods(Long goodsId) {
        int i = goodsMapper.deleteById(goodsId);
        if(i == 0) throw new GlobalException("下架失败");
    }

    @Override
    public void updateGoods(Goods goods) {
        int i = goodsMapper.updateById(goods);
        if(i == 0) throw new GlobalException("更新失败");
    }

}
